package java6681.lesson14;

import java.io.*;
import java.util.Enumeration;
import java.util.Properties;

/**
 * @author Junichiro
 * @description
 * @date 2021-06-19 12:24
 **/

public class test {
    public static void main(String[] args) throws IOException {
//        Properties pps = new Properties();
//        pps.load(new FileInputStream("config/oneClient6681.properties"));
//        Enumeration enum1 = pps.propertyNames();//得到配置文件的名字
//        while (enum1.hasMoreElements()) {
//            String strKey = (String) enum1.nextElement();
//            String strValue = pps.getProperty(strKey);
//            System.out.println(strKey + "=" + strValue);
//        }
        String port = GetValueByKey("config/oneClient6681.properties", "port");
        System.out.println(Integer.parseInt(port));
    }

    public static String GetValueByKey(String filePath, String key) {
        Properties pps = new Properties();
        try {
            InputStream in = new BufferedInputStream(new FileInputStream(filePath));
            pps.load(in);
            String value = pps.getProperty(key);
//            System.out.println(key + " = " + value);
            return value;

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
